package com.bosssoft.controller;

import com.bosssoft.entity.dto.FibBudgetDTO;
import com.bosssoft.entity.vo.FibBudgetVO;
import com.bosssoft.enums.BgtCode;
import com.bosssoft.response.Result;
import com.bosssoft.service.FibBudgetService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 项昊天
 * @create 2021/8/25 16:32
 */
@RestController
@Slf4j
@RequestMapping("/budget")
public class BudgetController {

  @Resource
  FibBudgetService budgetService;

  @PostMapping
  @ApiOperation("通过id查询预算记录")
  public Result getBgtById(@RequestParam("bgtId") Long bgtId) {

    FibBudgetDTO budgetDTO = budgetService.selectById(bgtId);

    if (budgetDTO == null) {
      log.info("来自BudgetController的消息: 没有这条记录");
      return Result.error(BgtCode.CANT_FOUND_RECORD);
    }

    FibBudgetVO budgetVO = new FibBudgetVO();
    BeanUtils.copyProperties(budgetDTO, budgetVO);
    log.info("通过预算id拿到了VO并成功返回!");
    return Result.ok().data("data", budgetVO);
  }

}
